import * as types from '../constants/ActionTypes';

export default function register(state = [], action = {}) {
    const {
        type, payload
    } = action;
    
    switch (type) {
       
        case types.REGISTER:
            return { ...payload };
            
        case types.REGISTER_SUCCESS:
            let successInfo = null;
            if (payload.results && payload.results.length) {
                successInfo = {
                    register_status : 1,
                    khid : payload.results[0].khid,
                    message : "注册成功"
                };
            }else{
                successInfo = {
                    register_status: -1,
                    message: "注册失败"
                };
            }   
            return {
               ...state,
               ...successInfo
            };
        case types.REGISTER_FAILURE:
            let failureInfo = {
                register_status: -1,
                message: payload.message||'网络连接失败'
            };
            return {
               ...state,
               ...failureInfo
            };  
        default:
            return state;
    }
}